package ngames.com.sushitv.view;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import ngames.com.sushitv.R;
import ngames.com.sushitv.interfaces.DialogButtonListener;
import ngames.com.sushitv.tools.ViewUtil;

/**
 * Created by Administrator on 2016/2/16.
 */
public class DialogApp extends Dialog implements View.OnClickListener {
    private Activity mActivity;
    private View mDialogView;
    private TextView mMessageTv;
    private Button mLeftBtn;
    private Button mRightBtn;
    private DialogButtonListener mLeftButtonListener;
    private DialogButtonListener mRightButtonListener;

    public DialogApp(Activity activity) {
        super(activity, R.style.style_custom_dialog);
        mActivity = activity;
        mDialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_app, null);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        setContentView(mDialogView);
        ViewUtil.setDialogWidth(activity, this, 0.85f, 0);
        mMessageTv = (TextView) mDialogView.findViewById(R.id.tv_message);
        mLeftBtn = (Button) mDialogView.findViewById(R.id.btn_left);
        mLeftBtn.setVisibility(View.GONE);
        mRightBtn = (Button) mDialogView.findViewById(R.id.btn_right);
        mRightBtn.setVisibility(View.GONE);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_left:
                if (mLeftButtonListener != null) {
                    mLeftButtonListener.onClick();
                }
                dismiss();
                break;
            case R.id.btn_right:
                if (mRightButtonListener != null) {
                    mRightButtonListener.onClick();
                }
                dismiss();
                break;
        }
    }

    public void setMessage(String message) {
        mMessageTv.setText(message);
    }

    public void setLeftBtn(String text, DialogButtonListener l) {
        mLeftBtn.setText(text);
        mLeftButtonListener = l;
        mLeftBtn.setVisibility(View.VISIBLE);
        mLeftBtn.setOnClickListener(this);
    }

    public void setRightBtn(String text, DialogButtonListener l) {
        mRightBtn.setText(text);
        mRightButtonListener = l;
        mRightBtn.setVisibility(View.VISIBLE);
        mRightBtn.setOnClickListener(this);
    }
}
